import time
from Unit_09.Base import Base
from selenium.webdriver.common.by import By

class Page(Base):
    # 定位器
    # 搜索框定位
    search_loc = (By.ID,'kw')
    # 百度一下定位
    search_button_loc = (By.ID,'su')
    # 设置定位
    setup_loc = (By.XPATH,'//*[@id="u"]/a[2]')
    set_gaoji_loc = (By.XPATH,'//*[@id="u"]/div/a[2]')
    set_shuru_loc = (By.ID,'adv_keyword')
    set_q3_loc = (By.NAME,'q3')

    # 页面元素的封装
    def search(self):
        # self.find_element(self.search_loc).send_keys('web端自动化')
        self.send_keys(self.search_loc,'web端自动化')

    def search_button(self):
        self.click(self.search_button_loc)

    def move_setup(self):
        self.move(self.setup_loc)

    def set_gaoji(self):
        self.click(self.set_gaoji_loc)

    def search_ctrl_a(self):
        self.Ctrl_Keys(self.search_loc,'a')

    def set_ctrl_c(self):
        self.Ctrl_Keys(self.search_loc,'c')

    def set_ctrl_v(self):
        self.Ctrl_Keys(self.set_shuru_loc,'v')

    def set_double(self):
        self.double_click(self.set_shuru_loc)

    def set_ctrl_c_q1(self):
        self.Ctrl_Keys(self.set_shuru_loc,'c')

    def set_ctrl_v_q3(self):
        self.Ctrl_Keys(self.set_q3_loc,'v')




    # 业务逻辑
    def baidu_luoji(self):
        self.get_url('http://www.baidu.com')
        # 搜索
        self.search()
        # 点击搜索按钮
        self.search_button()
        # 全选搜索框
        self.search_ctrl_a()
        # 复制搜索框
        self.set_ctrl_c()
        # 悬浮设置
        self.move_setup()
        # 点击高级搜索
        self.set_gaoji()
        # 粘贴q1
        self.set_ctrl_v()
        # 双击q1
        self.set_double()
        # 复制双击的q1
        self.set_ctrl_c_q1()
        # 粘贴到q3
        self.set_ctrl_v_q3()
